package pl.iachoo.ctl.tabory.ui.actions;

import org.apache.log4j.Logger;
import org.eclipse.jface.action.Action;
import org.eclipse.ui.IWorkbenchWindow;

public class OpenViewEditorAction extends Action {

	private final Logger log = Logger.getLogger(OpenViewEditorAction.class);

	private final IWorkbenchWindow window;
	private final String viewId;

	public OpenViewEditorAction(final IWorkbenchWindow window,
			final String label, final String viewId) {
		this.window = window;
		this.viewId = viewId;
		this.setText(label);
		this.setId(viewId);
	}

	@Override
	public void run() {
		if (this.window != null) {
			try {
				this.window.getActivePage().showView(this.viewId);
			} catch (final Exception e) {
				this.log.error(e.getMessage(), e);
			}
		}
	}
}